/**
 * @Description: 系统通用类型定义
 * @Author: lujq
 * @Date: 2025-08-25
 * @LastEditors: lujq
 * @LastEditTime: 2025-08-25 14:30:00
 */

// 基础响应类型
export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
  success: boolean
}

// 分页参数
export interface PageParams {
  page: number
  pageSize: number
  total?: number
}

// 分页响应
export interface PageResponse<T> {
  total: number
  list: T[]
  pagination: PageParams
}

// 客户信息
export interface Customer {
  id: string
  name: string
  company: string
  phone: string
  email: string
  address: string
  province: string
  city: string
  district: string
  customerType: 'individual' | 'enterprise'
  level: 'bronze' | 'silver' | 'gold' | 'diamond'
  status: 'active' | 'inactive' | 'blacklist'
  totalOrders: number
  totalAmount: number
  lastOrderDate: string
  salesManager: string
  paymentTerms: string
  lastContactDate: string
  preferredProducts: string[]
  createTime: string
  updateTime: string
  remark?: string
  // 企业客户扩展字段
  industry?: string
  companySize?: string
  legalPerson?: string
  registeredCapital?: string
  establishedDate?: string
  creditRating?: string
  businessLicense?: string
  taxNumber?: string
  website?: string
}

// 订单信息
export interface Order {
  id: string
  orderNo: string
  customerId: string
  customerName: string
  products: OrderProduct[]
  totalAmount: number
  discountAmount: number
  finalAmount: number
  status: 'pending' | 'confirmed' | 'production' | 'shipped' | 'delivered' | 'cancelled'
  paymentStatus: 'unpaid' | 'partial' | 'paid' | 'refunded'
  deliveryDate: string
  createTime: string
  updateTime: string
  remark?: string
}

/**
 * 收款记录
 */
export interface Receipt {
  id: string
  orderId: string
  orderNo: string
  customerId: string
  customerName: string
  amount: number
  receiptDate: string
  method?: string
  remark?: string
  createTime: string
  updateTime: string
}
// 订单产品
export interface OrderProduct {
  id: string
  productId: string
  productName: string
  specification: string
  quantity: number
  unit: string
  unitPrice: number
  totalPrice: number
  fabricType: string
  color: string
  width: number
  weight: number
}

// 面料产品信息
export interface FabricProduct {
  id: string
  name: string
  code: string
  category: string
  fabricType: string
  material: string
  color: string
  width: number
  weight: number
  thickness: number
  density: number
  unitPrice: number
  unit: string
  stock: number
  minOrder: number
  images: string[]
  description: string
  status: 'active' | 'inactive'
  createTime: string
  updateTime: string
}

// 产品信息（新的产品管理模块）
export interface Product {
  id: string
  productCode: string
  name: string
  category: string
  specification: string
  price: number
  stock: number
  sales: number
  status: 'active' | 'inactive'
  material?: string
  width?: string
  weight?: string
  density?: string
  color?: string
  origin?: string
  image?: string
  description?: string
  orderCount?: number
  customerCount?: number
  createTime: string
  updateTime: string
}

// 销售数据
export interface SalesData {
  date: string
  amount: number
  orders: number
  customers: number
}

// 客户分析数据
export interface CustomerAnalytics {
  totalCustomers: number
  newCustomers: number
  activeCustomers: number
  customerGrowth: number
  levelDistribution: {
    bronze: number
    silver: number
    gold: number
    diamond: number
  }
  regionDistribution: {
    province: string
    count: number
  }[]
}

// 订单统计数据
export interface OrderStatistics {
  totalOrders: number
  totalAmount: number
  avgOrderAmount: number
  orderGrowth: number
  statusDistribution: {
    pending: number
    confirmed: number
    production: number
    shipped: number
    delivered: number
    cancelled: number
  }
}

// 用户信息
export interface User {
  id: string
  username: string
  name: string
  email: string
  phone: string
  avatar: string
  role: string
  permissions: string[]
  status: 'active' | 'inactive'
  lastLoginTime: string
  createTime: string
}

// 菜单项
export interface MenuItem {
  id: string
  name: string
  path: string
  icon?: string
  component?: string
  children?: MenuItem[]
  meta?: {
    title: string
    requireAuth?: boolean
    permissions?: string[]
  }
}

// 图表数据
export interface ChartData {
  name: string
  value: number
  [key: string]: any
}

// 表格列配置
export interface TableColumn {
  prop: string
  label: string
  width?: number
  minWidth?: number
  fixed?: boolean | 'left' | 'right'
  sortable?: boolean
  formatter?: (row: any, column: any, cellValue: any) => string
}

// 搜索表单
export interface SearchForm {
  keyword?: string
  status?: string
  dateRange?: [string, string]
  [key: string]: any
}

// 操作按钮
export interface ActionButton {
  label: string
  type?: 'primary' | 'success' | 'warning' | 'danger' | 'info'
  icon?: string
  permission?: string
  handler: (row: any) => void
}

// 看板配置
export interface DashboardConfig {
  id: string
  name: string
  layout: {
    x: number
    y: number
    w: number
    h: number
    i: string
  }[]
  widgets: DashboardWidget[]
}

// 看板组件
export interface DashboardWidget {
  id: string
  type: 'chart' | 'table' | 'card' | 'text'
  title: string
  config: any
  dataSource: string
}

/**
 * @description 信用评估参数配置
 */
export interface CreditAssessmentConfig {
  // 各评估因素的权重，0-100，总建议为100
  creditScoreWeight: number // 信用评分（例如历史逾期、授信纪录）
  orderHistoryWeight: number // 历史订单量/金额
  paymentPunctualityWeight: number // 回款及时性
  relationshipWeight: number // 合作年限/黏性
  complaintWeight: number // 投诉/售后情况（权重通常偏低）
}

/**
 * @description 跟进提醒配置
 */
export interface RemindConfig {
  // 提前量（单位：天）
  contractExpireAdvanceDays: number // 合同到期提前提醒
  receivableDueAdvanceDays: number // 应收款到期提前提醒
  customerFollowupAdvanceDays: number // 客户定期回访提前提醒
}

/**
 * @description 系统设置（仅与本需求相关的子集）
 */
export interface SystemSettings {
  id: string
  creditAssessment: CreditAssessmentConfig
  remind: RemindConfig
  // 可扩展：basic、business、notification 等其他设置
  createTime: string
  updateTime: string
}
